//
//  NewsTableViewCell.m
//  CarHome
//
//  Created by apple on 15/3/21.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "NewsTableViewCell.h"

@implementation NewsTableViewCell
- (void)dealloc
{
    [_dateLabel release];
    [_imageview release];
    [_judgeLabel release];
    [_titleLabel release];
    [super dealloc];
}
- (void)awakeFromNib {
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.bigView = [[UIView alloc]init];
        [self.contentView addSubview:self.bigView];
        [_bigView release];
        
        self.imageview = [[UIImageView alloc]init];
        [self.bigView addSubview:self.imageview];
        [_imageview release];
        
        self.titleLabel = [[UILabel alloc]init];
        [self.bigView addSubview:self.titleLabel];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.font = [UIFont systemFontOfSize:13];
        [_titleLabel release];
        
        self.dateLabel = [[UILabel alloc]init];
        [self.bigView addSubview:self.dateLabel];
        [_dateLabel release];
        
        self.judgeLabel = [[UILabel alloc]init];
        [self.bigView addSubview:self.judgeLabel];
        [_judgeLabel release];
    }
    
    return self;

}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.bigView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    
    self.imageview.frame = CGRectMake(10, 10, 130, self.contentView.frame.size.height - 20);
    
    self.titleLabel.frame = CGRectMake(self.imageview.frame.size.width + self.imageview.frame.origin.x + 10, 10, 190, 40);
    
    
    self.dateLabel.frame = CGRectMake(self.imageview.frame.size.width + self.imageview.frame.origin.x + 10, self.bigView.frame.size.height - 30, 110, 20);
    
    self.judgeLabel.frame = CGRectMake(self.bigView.frame.size.width - 90, self.contentView.frame.size.height - 30, 80, 20);
    self.judgeLabel.font = [UIFont systemFontOfSize:12];
    self.judgeLabel.textColor = [UIColor grayColor];
    
    
//    self.bigView.backgroundColor = [UIColor greenColor];
//    self.imageview.backgroundColor = [UIColor blueColor];
//    self.titleLabel.backgroundColor = [UIColor yellowColor];
//    self.dateLabel.backgroundColor = [UIColor orangeColor];
//    self.judgeLabel.backgroundColor = [UIColor cyanColor];
    
    
    
    
}
#pragma mark 重写set方法
- (void)setData:(NewsData *)data
{
    if (_data != data) {
        [_data release];
        _data = [data retain];
    }
    
  
    if ([self.data.smallpic isEqualToString:@""]) {
        
        [self.imageview setImage:[UIImage imageNamed:@"mine.png"]];
        
        
    }
    else
    {
    NSURL *url = [NSURL URLWithString:self.data.smallpic];
    [self.imageview setImageWithURL:url];
    }
    self.titleLabel.text = self.data.title;
    self.dateLabel.text = self.data.time;
  int count = [self.data.mediatype intValue];
    
    NSLog(@"%d", [self.data.mediatype intValue]);
    
    
    switch (count) {
        case 3:
            self.judgeLabel.text = [[self.data.replycount stringValue] stringByAppendingString:@"次播放"];
            break;
       case 5:
            self.judgeLabel.text = [[self.data.replycount stringValue] stringByAppendingString:@"回帖"];
            
        default:
            self.judgeLabel.text = [[self.data.replycount stringValue] stringByAppendingString:@"评论"];
            break;
    }
    
    
    
    
    
    
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
